package com.cskaoyan.service;

import com.cskaoyan.bean.MarketTopic;
import com.cskaoyan.bean.MarketTopicExample;
import com.cskaoyan.bean.MarketTopicGoods;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketTopicMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * title VxTopicServiceImpl
 * @description <TODO description class purpose>
 * @author ZCZ
 * @version 1.0.0
 * @create 2022/9/11 23:02
 **/
@Service
public class VxTopicServiceImpl implements VxTopicService {
    @Autowired
    MarketTopicMapper marketTopicMapper;


    @Override
    public CommonData<MarketTopic> list(BasePageInfo info) {
        PageHelper.startPage(info.getPage(),info.getLimit());
        MarketTopicExample marketTopicExample = new MarketTopicExample();
        marketTopicExample.setDistinct(true);

        List<MarketTopic> marketTopicList = marketTopicMapper.selectByExample(marketTopicExample);
        PageInfo pageInfo = new PageInfo(marketTopicList);
        Integer total=(int)pageInfo.getTotal();
        int pages = pageInfo.getPages();
        CommonData<MarketTopic> marketTopicCommonData = new CommonData<>();
        marketTopicCommonData.setList(marketTopicList);
        marketTopicCommonData.setPages(total);
        marketTopicCommonData.setPages(pages);
        return marketTopicCommonData;
    }

    @Override
    public MarketTopicGoods detail(int id) {
        MarketTopicGoods marketTopicGoods = new MarketTopicGoods();
        MarketTopic marketTopic = marketTopicMapper.selectByPrimaryKey(id);
        marketTopicGoods.setTopic(marketTopic);
        marketTopicGoods.setGoods(marketTopic.getGoods());
        return marketTopicGoods;
    }

    @Override
    public CommonData<MarketTopic> related(int id) {
        PageHelper.startPage(1,4);
        MarketTopicExample marketTopicExample = new MarketTopicExample();
        marketTopicExample.setDistinct(true);

        List<MarketTopic> marketTopicList = marketTopicMapper.selectByExample(marketTopicExample);
        PageInfo pageInfo = new PageInfo(marketTopicList);
        Integer total=(int)pageInfo.getTotal();
        int pages = pageInfo.getPages();
        CommonData<MarketTopic> marketTopicCommonData = new CommonData<>();
        marketTopicCommonData.setList(marketTopicList);
        marketTopicCommonData.setTotal(total);
        marketTopicCommonData.setPages(pages);
        marketTopicCommonData.setPage(1);
        marketTopicCommonData.setLimit(4);

        return marketTopicCommonData;
    }
}
